//
//  RBGetCouponListCell.m
//  zhongzhenglu
//
//  Created by XL on 2022/8/30.
//

#import "RBGetCouponListCell.h"

@interface RBGetCouponListCell()

@property(nonatomic, strong)IBOutlet UIView *bgView;
@property(nonatomic, strong)IBOutlet UILabel *unitL;
@property(nonatomic, strong)IBOutlet UILabel *priceL;
@property(nonatomic, strong)IBOutlet UILabel *titleL;
@property(nonatomic, strong)IBOutlet UILabel *desL;
@property(nonatomic, strong)IBOutlet UILabel *scopeL;
@property(nonatomic, strong)IBOutlet UIImageView *lineImgView;
@property(nonatomic, strong)IBOutlet UIButton *buyBtn;
@property(nonatomic, strong)IBOutlet UILabel *countL;

@property(nonatomic, strong) RBCellModel *cellModel;

@end

@implementation RBGetCouponListCell

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self zoomSubViewsWithSelf];
    
    self.lineImgView.image = [UIImage imageNamed:@"takeCouponLineBlue"];

    self.priceL.adjustsFontSizeToFitWidth = YES;
}

- (void)setCellModel:(RBCellModel *)cellModel
{
    _cellModel = cellModel;
    RBGetCouponModel *model = cellModel.cellData;
    
    
    self.priceL.text = model.price;
    self.titleL.text = model.name;
    self.desL.text = model.desc;
    self.scopeL.text = [NSString stringWithFormat:@"　%@　",model.type];
    self.countL.text = [NSString stringWithFormat:@"剩余%@",model.shuliang];
    if ([model.qudao_type isEqualToString:@"1"]) {
        if ([model.state isEqualToString:@"0"]) {
            [self.buyBtn setTitle:@"立即领取" forState:UIControlStateNormal];
        } else {
            [self.buyBtn setTitle:@"已领取" forState:UIControlStateNormal];
        }
        self.unitL.textColor = self.priceL.textColor = self.buyBtn.backgroundColor = [UIColor colorWithHexString:@"#FF9242"];
        self.bgView.backgroundColor = [UIColor colorWithHexString:@"#F9F2EC"];
    } else {
        [self.buyBtn setTitle:@"立即购买" forState:UIControlStateNormal];
        self.unitL.textColor = self.priceL.textColor = self.buyBtn.backgroundColor = [UIColor colorWithHexString:@"#688AE7"];
        self.bgView.backgroundColor = [UIColor colorWithHexString:@"#F0F4F8"];
    }
    
    [self bringSubviewToFront:self.bgView];
}
- (IBAction)clickBuyBtn:(UIButton *)sender {
    RBGetCouponModel *model = self.cellModel.cellData;
    if ([model.state isEqualToString:@"1"] && [model.qudao_type isEqualToString:@"1"]) {
        return;
    }
    if(self.cellModel.eventBlock1)
    {
        self.cellModel.eventBlock1(0, 0, model);
    }
}

@end
